package com.ruoyi.project.meal.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.meal.domain.Meal;
import com.ruoyi.project.meal.service.IMealService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 充值套餐Controller
 * 
 * @author wyh
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/meal/meal")
public class MealController extends BaseController
{
    @Autowired
    private IMealService mealService;

    /**
     * 查询充值套餐列表
     */
    @PreAuthorize("@ss.hasPermi('meal:meal:list')")
    @GetMapping("/list")
    public TableDataInfo list(Meal meal)
    {
        startPage();
        List<Meal> list = mealService.selectMealList(meal);
        return getDataTable(list);
    }

    /**
     * 导出充值套餐列表
     */
    @PreAuthorize("@ss.hasPermi('meal:meal:export')")
    @Log(title = "充值套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Meal meal)
    {
        List<Meal> list = mealService.selectMealList(meal);
        ExcelUtil<Meal> util = new ExcelUtil<Meal>(Meal.class);
        util.exportExcel(response, list, "充值套餐数据");
    }

    /**
     * 获取充值套餐详细信息
     */
    @PreAuthorize("@ss.hasPermi('meal:meal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mealService.selectMealById(id));
    }

    /**
     * 新增充值套餐
     */
    @PreAuthorize("@ss.hasPermi('meal:meal:add')")
    @Log(title = "充值套餐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Meal meal)
    {
        return toAjax(mealService.insertMeal(meal));
    }

    /**
     * 修改充值套餐
     */
    @PreAuthorize("@ss.hasPermi('meal:meal:edit')")
    @Log(title = "充值套餐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Meal meal)
    {
        return toAjax(mealService.updateMeal(meal));
    }

    /**
     * 删除充值套餐
     */
    @PreAuthorize("@ss.hasPermi('meal:meal:remove')")
    @Log(title = "充值套餐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mealService.deleteMealByIds(ids));
    }
}
